﻿using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using System;

namespace AsNum.Common.EntLib.Validation.Adapters {
    /// <summary>
    /// 
    /// </summary>
    public class StringLengthClientAdapter : BaseClientAdapter<StringLengthValidatorData> {

        public StringLengthClientAdapter(StringLengthValidatorData data , Dictionary<string , Tuple<string, string>> map , bool isSub = false)
            : base ( data, map , isSub ) {

            if (this.ValidatorData.LowerBoundType != RangeBoundaryType.Ignore) {
                this.AddRule(RuleKeys.Min, this.ValidatorData.LowerBound.ToString());
                this.AddRule(RuleKeys.IncludeMin, (this.ValidatorData.LowerBoundType == RangeBoundaryType.Inclusive).JsBool());
            }

            if (this.ValidatorData.UpperBoundType != RangeBoundaryType.Ignore) {
                this.AddRule(RuleKeys.Max, this.ValidatorData.UpperBound.ToString());
                this.AddRule(RuleKeys.IncludeMax, (this.ValidatorData.UpperBoundType == RangeBoundaryType.Inclusive).JsBool());
            }
        }


        public override RuleTypes RuleType {
            get {
                return RuleTypes.Length;
            }
        }
    }
}
